Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

291
Views
Put array like [1,3] give the error 'Uncaught SyntaxError: Invalid destructuring assignment target'

I write a bubble sort function to arrange numbers in the array, but when I put array like [1,3] ,vscode and chrome give me the

Identifier expected.javascript OR Uncaught SyntaxError: Invalid destructuring assignment target

here is the full code

function bubbleg(arr) {

  var len = arr.length;
  for (var i = 0; i < len - 1; i++) {
    for (var j = 0; j < len - 1 - i; j++) {
      if (arr[j] > arr[j + 1]) {
        var temp = arr[j];
        arr[j] = arr[j + 1];
        arr[j + 1] = temp;

      }
    }
  }
  return arr;
}

function bubbleg([1, 3]);

After make a change, like

num= [1,3] function bubbleg(num);

Everything is good, but why we can not put the something like bubbleg([1,3])? Is there any books so when I look it up with some bugs list in it ?

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

remove function keyword in calling your function. function is keyword used to declare function, not to call it.

function bubbleg(arr) {
  var len = arr.length;
  for (var i = 0; i < len - 1; i++) {
    for (var j = 0; j < len - 1 - i; j++) {
      if (arr[j] > arr[j + 1]) {
        var temp = arr[j];
        arr[j] = arr[j + 1];
        arr[j + 1] = temp;

      }
    }
  }
  return arr;
}
bubbleg([1, 3]);
about 4 years ago · Juan Pablo Isaza Report

0

that is because you're not calling the function bubbleg correctly

function bubbleg([1,2])

should be

bubbleg([1,2])
about 4 years ago · Juan Pablo Isaza Report

0

It is not about the [1, 3] argument you pass. But how you call the function.

Here is the correct code:

function bubbleg(arr) {

    var len = arr.length;
    for (var i = 0; i < len - 1; i++) {
        for (var j = 0; j < len - i - 1; j++) {
            if (arr[j] > arr[j + 1]) {
                var temp = arr[j];
                arr[j] = arr[j + 1];
                arr[j + 1] = temp;

            }
        }
    }
    return arr;
} 
        
 console.log(bubbleg( [3,1] ));

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!